import 'dart:math';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:provider/provider.dart';
import 'package:todo_list/i10n/localization_intl.dart';
import 'package:todo_list/model/global_model.dart';
import 'package:todo_list/model/main_page_model.dart';
import 'package:todo_list/pages/navigator/nav_page.dart';
import 'package:todo_list/pages/navigator/settings/setting_page.dart';
import 'package:todo_list/utils/shared_util.dart';
import 'package:todo_list/widgets/animated_floating_button.dart';
import 'package:todo_list/widgets/menu_icon.dart';
import 'package:todo_list/widgets/synchronize_widget.dart';
import 'package:url_launcher/url_launcher.dart';

class MainPage extends StatelessWidget {

  Widget build(BuildContext context) {
    final model = Provider.of<MainPageModel>(context);
    final globalModel = Provider.of<GlobalModel>(context);
    final size = MediaQuery.of(context).size;
    final canHideWidget = model.canHideWidget;
    model.setContext(context, globalModel: globalModel);
    globalModel.setMainPageModel(model);

    return GestureDetector(
      //onLongPress: () => model.logic.onBackGroundTap(globalModel),
      child: Container(
        decoration: model.logic.getBackground(globalModel),
        child: Scaffold(
            key: model.scaffoldKey,
            backgroundColor: Colors.transparent,
            appBar: AppBar(
              backgroundColor: Colors.transparent,
              elevation: 0,
              title: Text(IntlLocalizations.of(context).appName),
              leading: !canHideWidget
                  ? FlatButton(
                      child: MenuIcon(globalModel.logic.getWhiteInDark()),
                      onPressed: () {
                        model.scaffoldKey.currentState.openDrawer();
                      },
                    )
                  : Container(),
              // actions: <Widget>[
              //   !canHideWidget
              //       ? IconButton(
              //           icon: Icon(
              //             Icons.search,
              //             size: 28,
              //             color: globalModel.logic.getWhiteInDark(),
              //           ),
              //           onPressed: () => model.logic.onSearchTap(),
              //         )
              //       : Container()
              // ],
            ),
            drawer: Drawer(
              child: NavPage(),
            ),
            // floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
            // floatingActionButtonLocation:
            //     FloatingActionButtonLocation.centerFloat,
            // floatingActionButton: !canHideWidget
            //     ? GestureDetector(
            //         onLongPress: () {
            //           showModalBottomSheet(
            //               context: context,
            //               builder: (ctx) {
            //                 return buildSettingListView(context, globalModel);
            //               });
            //         },
            //         child: AnimatedFloatingButton(
            //           bgColor: globalModel.isBgChangeWithCard
            //               ? model.logic.getCurrentCardColor()
            //               : null,
            //         ),
            //       )
            //     : Container(),
            body: Column(
              children: <Widget>[
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "公告",
                      ),
                      IconButton(onPressed: () {}, icon: Icon(Icons.close))
                    ],
                  ),
                  margin: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(color: Colors.grey),
                ),
                Container(
                  child: Text(
                   model.notificationStr
                  ),
                  margin: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(color: Colors.grey),
                ),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "游戏",
                      ),
                      IconButton(onPressed: () {}, icon: Icon(Icons.close))
                    ],
                  ),
                  margin: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(color: Colors.grey),
                ),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Container(
                        width: 120,
                        height: 100,
                        child: Text(
                          "不可能完成的任务",
                        ),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(color: Colors.grey),
                      ),
                      Container(
                        width: 120,
                        height: 100,
                        child: Text(
                          "猜数字游戏",
                        ),
                        decoration: BoxDecoration(color: Colors.grey),
                        alignment: Alignment.center,
                      )
                    ],
                  ),
                  margin: EdgeInsets.all(10.0),
                ),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "聊天",
                      ),
                      IconButton(onPressed: () {}, icon: Icon(Icons.close))
                    ],
                  ),
                  margin: EdgeInsets.all(10.0),
                  decoration: BoxDecoration(color: Colors.grey),
                ),
                Container(
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              "张三",
                            ),
                            Chip(
                              label: Text("未读1条"),
                            ),
                          ],
                        ),
                        decoration: BoxDecoration(color: Colors.white),
                        margin: EdgeInsets.all(1.0),
                      ),
                      Container(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              "李四",
                            ),
                            Chip(
                              label: Text("未读1条"),
                            ),
                          ],
                        ),
                        decoration: BoxDecoration(color: Colors.white),
                        margin: EdgeInsets.all(1.0),
                      ),
                      Container(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              "王五",
                            ),
                            Chip(
                              label: Text("未读1条"),
                            ),
                          ],
                        ),
                        decoration: BoxDecoration(color: Colors.white),
                        margin: EdgeInsets.all(1.0),
                      ),
                    ],
                  ),
                  margin: EdgeInsets.all(10.0),
                ),
              ],
            )

            // TextButton(
            //   onPressed: () => {model.logic.onIncContri()},
            //   child: Text("签到"),
            // ),
            // TextButton(
            //   onPressed: () => {launch("https://2020cn.cn/game")},
            //   child: Text("游戏"),
            // ),
            // TextButton(
            //   onPressed: () => {model.logic.onLogoutPressed()},
            //   child: Text("退出登录"),
            // )
            ),
      ),
    );
  }

  MainPage();
}
